package com.chmingx.JavaBasic.exception;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/**
 * try catch 处理异常
 */
public class TryCatchException {
    public static void main(String[] args) {
        byte[] bs = toGBK("中文");
        System.out.println(Arrays.toString(bs));
    }

    static byte[] toGBK(String s) {
        // try-catch语法处理异常
        try {
            return s.getBytes("GBK");
        } catch (UnsupportedEncodingException e) {
            System.out.println(e);
            e.printStackTrace();
            return s.getBytes();
        }
    }
}
